from dbfpy import dbf
import os,os.path
import csv
import sys

def readDBF(filename):
	csvDir = os.path.split(filename)[0]
	fname = os.path.split(filename)[1]
	csvName = csvDir+"/"+os.path.splitext(fname)[0]+".csv"
	print "csvName="+csvName
	writer = csv.writer(open(csvName,"wb"))
	db = dbf.Dbf(filename)
	for rec in db:
		record = []
		for fieldName in db.fieldNames:
			record.append(rec[fieldName])
		writer.writerow(record)
		
if __name__ == '__main__':
	dbfFile = sys.argv[1]
	readDBF(dbfFile)
